package com.alameda.controller.menu;

import com.alameda.api.menu.MenuService;
import com.alameda.menu.dto.MenuDTO;
import com.alameda.menu.pojo.MenuDO;
import com.alameda.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 菜单 前端控制层
 *
 * @author Lv
 * @date 2024/05/09
 */
@Api(tags = "菜单")
@RestController
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 读取菜单树
     *
     * @return
     */
    @ApiOperation("读取菜单树")
    @PostMapping("/load_menu")
    public Result<?> loadMenu() {
        return Result.success(menuService.loadMenu());
    }

    /**
     * 读取菜单信息列表
     *
     * @param menuDTO 菜单数据传递对象
     * @return
     */
    @ApiOperation("读取菜单信息列表")
    @PostMapping("/list_menu_info")
    public Result<?> listMenuInfo(@RequestBody MenuDTO menuDTO) {
        return Result.success(menuService.listMenuInfo(menuDTO));
    }

    /**
     * 添加菜单
     *
     * @param menuDO 菜单实体类
     * @return
     */
    @ApiOperation("添加菜单")
    @PostMapping("/save_or_update")
    public Result<?> saveOrUpdate(@RequestBody MenuDO menuDO) {
        return Result.success(menuService.saveOrUpdate(menuDO));
    }

    /**
     * 删除菜单
     *
     * @param idList 菜单id集合
     * @return
     */
    @ApiOperation("删除菜单")
    @PostMapping("/remove")
    public Result<?> removeByIdList(@RequestBody List<Long> idList) {
        return Result.success(menuService.removeByIdList(idList));
    }

    /**
     * 导出excel
     *
     * @param menuDTO 菜单数据传递对象
     */
    @ApiOperation("导出excel")
    @PostMapping("/export")
    public void export(@RequestBody MenuDTO menuDTO) {
        menuService.export(menuDTO);
    }

    /**
     * 导出菜单json
     */
    @ApiOperation("导出菜单json")
    @PostMapping("/export_menu")
    public void exportMenu() {
        menuService.exportMenu();
    }
}

